package com.amoyt.project.controller.admin;

import com.amoyt.project.domain.dto.query.LogPageQuery;
import com.amoyt.project.domain.res.Result;
import com.amoyt.project.exception.BusinessException;
import com.amoyt.project.exception.enums.BusinessExceptionEnum;
import com.amoyt.project.service.admin.OperationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date: 2025/8/24
 * @Time: 11:21
 * @Author: TQ_QT
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping("/admin/log")
@Tag(name = "操作日志接口",description = "操作日志接口")
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    /**1
     * 获取操作日志列表
     * @param query
     * @return
     */
    @PostMapping("/list")
    @Parameter(name = "token",description = "访问令牌",required = true,in = ParameterIn.HEADER)
    @Operation(summary = "操作日志列表",method = "POST")
    @PreAuthorize("hasAnyRole('super_admin','prov_admin','city_admin','region_admin','village_admin')")
    public Result list(@RequestBody LogPageQuery query){
        if(query == null || query.getPage() == null || query.getPageSize() == null){
            throw new BusinessException(BusinessExceptionEnum.PARAM_ERROR);
        }
        return operationLogService.list(query);
    }

    /**
     * 删除日志列表
     * @param logIds
     * @return
     */
    @Operation(summary = "删除日志列表",method = "DELETE")
    @DeleteMapping("/delete/{logIds}")
    @Parameter(name="token",description = "访问令牌",required = true,in = ParameterIn.HEADER)
    @PreAuthorize("hasAnyRole('super_admin')")
    public Result delete(@PathVariable List<Long> logIds){
        if(logIds == null || logIds.size() == 0){
            throw new BusinessException(BusinessExceptionEnum.PARAM_ERROR);
        }
        return operationLogService.delete(logIds);
    }
}
